package com.cn.boot.student.controller.rbac;

import com.cn.boot.student.util.CommonResult;
import com.cn.boot.student.entity.RoleEntity;
import com.cn.boot.student.service.rbac.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色控制层
 * Created by luosir in 2021/2/22
 */
@RestController
@Api(tags = "角色管理")
@RequestMapping("/admin/role")
public class RoleController {
    @Autowired
    private IRoleService iRoleService;
    /**
     * 查询所有
     */
    @PostMapping("/findAll")
    @PreAuthorize("hasAuthority('sys:role:read')")
    @ApiOperation(value = "查询所有数据")
    public CommonResult findAll(RoleEntity roleEntity){
        return iRoleService.findAll(roleEntity);
    }
    /**
     * 根据id查询角色
     */
    @PostMapping("/findById")
    @PreAuthorize("hasAuthority('sys:role:read')")
    @ApiOperation(value ="根据id查询角色")
    public CommonResult findById(Integer id){
        return iRoleService.findById(id);
    }
    /**
     * 添加数据
     */
    @PostMapping("/add")
    @PreAuthorize("hasAuthority('sys:role:add')")
    @ApiOperation(value ="添加数据")
    public CommonResult add(RoleEntity roleEntity){
        return iRoleService.add(roleEntity);
    }

    /**
     * 更新数据
     */
    @PostMapping("/update")
    @PreAuthorize("hasAuthority('sys:role:update')")
    @ApiOperation(value ="更新数据")
    public CommonResult update(RoleEntity roleEntity){
        return iRoleService.update(roleEntity);
    }
    /**
     * 删除数据
     */
    @DeleteMapping("/del")
    @PreAuthorize("hasAuthority('sys:role:del')")
    @ApiOperation(value ="删除数据")
    public CommonResult del(Integer id){
        return iRoleService.del(id);
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/dels")
    @PreAuthorize("hasAuthority('sys:role:del')")
    @ApiOperation(value ="批量删除")
    public CommonResult dels(List<Integer> ids){
        return iRoleService.dels(ids);
    }
}
